package myBatis.dao;

import myBatis.domain.User;
import myBatis.util.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class IUserDAOImpl implements IUserDAO{
    @Override
    public User selectOne(Long id) {
        SqlSession ss = MyBatisUtils.openSS();
        User u = ss.selectOne("myBatis.mapper.UserMapper.selectOne",id);
        ss.close();
        return u;
    }

    @Override
    public List<User> selectAll() {
        SqlSession ss = MyBatisUtils.openSS();
        List<User> l = ss.selectList("myBatis.mapper.UserMapper.selectAll");
        ss.close();
        return l;
    }

    @Override
    public void insert(User user) {
        SqlSession ss = MyBatisUtils.openSS();
        ss.insert("myBatis.mapper.UserMapper.insert",user);
        ss.commit();
        ss.close();
    }

    @Override
    public void delete(Long id) {
        SqlSession ss = MyBatisUtils.openSS();
        ss.delete("myBatis.mapper.UserMapper.delete",id);
        ss.commit();
        ss.close();
    }

    @Override
    public void upDate(User user) {
        SqlSession ss = MyBatisUtils.openSS();
        ss.update("myBatis.mapper.UserMapper.update",user);
        ss.commit();
        ss.close();
    }
}
